package com.mjh.listener;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.log4j.Logger;


public class SessionListener implements HttpSessionListener {

	private static int sessionNum = 0;
	
	public static Logger log = Logger.getLogger(SessionListener.class);
	
    public SessionListener() {
        
    }

    public void sessionCreated(HttpSessionEvent arg0) {
    	sessionNum ++;
    	arg0.getSession().getServletContext().setAttribute("onlineNum", sessionNum);
    	log.info("新建会话！");
    }

    public void sessionDestroyed(HttpSessionEvent arg0) {
    	sessionNum --;
    	arg0.getSession().getServletContext().setAttribute("onlineNum", sessionNum);
    	log.info("注销会话！");
    }
	
}
